<!-- 工单设置 -->
<template>
  <div class="app-container">
    <div class="container">
      <div class="search-and-button noLeftInput">
        <div class="btnList">
          <ImportFile url="/basic/equip/import" @getTableInfo="getTableInfo" />
          <el-button type icon="el-icon-refresh-left" @click="$router.push('/reload')">刷新</el-button>
          <el-button type icon="el-icon-more">更多</el-button>
          <el-button type="primary" plain :icon="!show ? 'el-icon-arrow-down' : 'el-icon-arrow-up'" @click="show = !show">查询条件</el-button>
        </div>
      </div>
      <transition name="el-zoom-in-top">
        <div v-show="show" class="more-search">
          <el-form :model="search" label-width="80px">
            <el-row>
              <el-col :xs="24" :xl="8" :md="8">
                <el-form-item label="工单描述" prop="workRemark">
                  <el-input v-model="search.workRemark" clearable placeholder="请输入" @keyup.enter.native="getTableInfo()" @clear="getTableInfo()" />
                </el-form-item>
              </el-col>
              <el-col :xs="24" :xl="8" :md="8">
                <el-form-item label="故障代码" prop="faultCode">
                  <el-input v-model="search.faultCode" clearable placeholder="请输入" @keyup.enter.native="getTableInfo()" @clear="getTableInfo()" />
                </el-form-item>
              </el-col>
              <el-col :xs="24" :xl="8" :md="8">
                <el-form-item label="协议信息" prop="protocol">
                  <el-input v-model="search.protocol" clearable placeholder="请输入" @keyup.enter.native="getTableInfo()" @clear="getTableInfo()" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </transition>
      <el-row class="table">
        <el-table ref="tableData" v-loading="loading" :data="tableData" stripe border @selection-change="handleSelectionChange">
          <el-table-column type="selection" align="center"></el-table-column>
          <el-table-column align="center" type="index" label="索引" width="60px" />
          <el-table-column v-for="item in fieldList" :key="item.id" :align="item.align || 'left'" :prop="item.code.split(':')[1]" :label="item.val" :min-width="item.width + 'px'" show-overflow-tooltip>
            <template #default="{ row }">
              <el-button v-if="item.code.split(':')[1] === 'equipName'" size="mini" type="text" @click="applyNoDetails(row)">{{ row.equipName }}</el-button>
              <span v-else-if="item.code.split(':')[1] === 'repairMethod'">{{ row.repairMethod == 0 ? '待确认' : row.repairMethod == 1 ? '内修':'外修' }}</span>
              <span v-else-if="item.code.split(':')[1] === 'status'">
                <span v-if="row.status == 1">新建</span>
                <span v-else-if="row.status == 2">已下达</span>
                <span v-else-if="row.status == 3">维修中</span>
                <span v-else>已完成</span>
              </span>
              <span v-else>{{ row[item.code.split(':')[1]] }}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <el-row>
        <div class="table-btn-box">
          <el-button @click="
                () => {
                  tableData.forEach(row => {
                    $refs['tableData'].toggleRowSelection(row, true)
                  })
                }
              ">选择全部</el-button>
          <el-button @click="
                () => {
                  tableData.forEach(row => {
                    $refs['tableData'].toggleRowSelection(row)
                  })
                }
              ">反向选择</el-button>
          <el-button>
            更多菜单
            <i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
        </div>
        <pagination ref="Pagination" :total="total" :current.sync="search.current" :size.sync="search.size" @pagination="getTableInfo" />
      </el-row>
    </div>
  </div>
</template>
<script>
import ImportFile from '@/components/ImportFile'
import Pagination from '@/components/Pagination'
import { mapGetters } from 'vuex'
export default {
  components: {
    Pagination,
    ImportFile
  },
  data() {
    return {
      defaultProps: {
        children: 'children',
        label: 'typeName'
      },
      defaultExpandKeys: ['-1'],
      breadcrumb: ['设备类型目录'],
      loading: false,
      tableData: [],
      multipleSelection: [],
      total: 0,
      search: {
        current: 1,
        size: 20,
        objNo: '',
        protocol: '',
        treeStr: '-1',
        faultCode: '',
        workRemark: '',
        beginDate: '',
        endDate: ''
      },
      show: false
    }
  },
  computed: {
    ...mapGetters(['compInfo'])
  },
  created() {},
  async mounted() {
    await this.getTableInfo()
  },
  methods: {
    /* 获取所有分页数据 */
    async getTableInfo(page = 1) {
      this.search.current = page
      this.loading = true
      const res = await this.$axios.post('/equip/work/set/list', this.search)
      if (res?.data.code === 200) {
        this.tableData = res.data.data.list
        this.total = res.data.data.total
        setTimeout(() => {
          this.loading = false
        }, 100)
      } else {
        this.loading = false
      }
    },
    /**
     * @description: 选中项
     * @param {*} val
     * @return {*}
     */
    handleSelectionChange(val) {
      this.multipleSelection = val
    }
  }
}
</script>
<style lang='scss' scoped>
</style>
